/**
 * Created by Administrator on 2018/11/15.
 */

$(function(){

    /*头部的关注*/
    $("#followIcon").on('click',function(){
    	if(userid != ''){
    		var authorid = $('#tuid').val();
    		var userid = $("#muid").val();
            var _this = $(this);
            var iconM = _this.find('.iconfont');
            if(_this.hasClass('personal-iconCl')){
                layer.open({
                    content: '确定取消关注吗?',
                    btn: ['确定', '取消'],
                    shadeClose: false,
                    yes: function (index) {
                    	 $.ajax({ 
        					 url: '/operate/'+ userid + '/cancel/' + authorid, 
        					 type: "POST",
        			         data: {},
        			         dataType: "json",//请求数据类型
        					 success: function(data){
        						 if(data.code == 0){
        							_this.removeClass('personal-iconCl');
    			                    iconM.html('&#xe604;');
    			                    layer.close(index);
        						 }else{
        							 if(data.code == 111){
        								 window.location.href='/signup';
        							 }else{
        								 sstb.dialog(data.msg);
        							 }
        						 }
        					 },
        					 error : function() {
        						 sstb.dialog("取消关注异常");
        					 }
        				 })	
                    },
                    no: function () {

                    }
                });
            }else{
            	$.ajax({ 
    				 url: '/operate/'+ userid + '/follow/' + authorid, 
    				 type: "POST",
    		         data: {},
    		         dataType: "json",//请求数据类型
    				 success: function(data){
    					 var result = data.data;
    					 if(data.code == 0){
    						 _this.addClass('personal-iconCl');
    				         iconM.html('&#xe669;');
    					 }else{
    						 sstb.dialog(data.msg);
    					 }
    				 },
    				 error : function() {
    					 sstb.dialog("关注失败");
    				 }
    			 })
            	
            	
                
            }
    	}else{
    		window.location.href = "/signup"
    	}
    })
})
